home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / SpriteWorld / SpriteWorld Files / BlitPixie / Sources / BlitPixieMask.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  16.2 KB  |  690 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    BlitPixieMask - a fast masked blitter
  3. //
  4. //    Ideas and code snippets contributed by:
  5. //        Ben Sharpe, Brigham Stevens, Sean Callahan, Joe Britt and Tim Collins
  6. //
  7. //    Portions are copyright: © 1991-94 Tony Myles
  8. ///--------------------------------------------------------------------------------------
  9.  
  10. #ifndef __BLITPIXIE__
  11. #include "BlitPixieHeader.h"
  12. #endif
  13.  
  14. #include "BlitPixieAsm.h"
  15.  
  16. #pragma mark *** PowerPC asm:
  17. #if USE_PPC_ASSEMBLY
  18.  
  19. ///--------------------------------------------------------------------------------------
  20. //        BlitPixieMask - PowerPC asm implementation by Anders F Björklund
  21. ///--------------------------------------------------------------------------------------
  22.  
  23. ASM_FUNC void BlitPixieMask(
  24.     register unsigned char *srcPixelP,        // r3
  25.     register unsigned char *dstPixelP,        // r4
  26.     register unsigned char *maskPixelP,        // r5
  27.     register unsigned long srcOffset,        // r6
  28.     register unsigned long dstOffset,        // r7
  29.     register unsigned short numBytesPerRow,    // r8
  30.     register unsigned short rowsToCopy)        // r9
  31. {
  32.     #define r_srcPixelP            r3
  33.     #define r_dstPixelP            r4
  34.     #define r_maskPixelP        r5
  35.     #define r_srcOffset            r6
  36.     #define r_dstOffset            r7
  37.     #define r_numBytesPerRow    r8
  38.     #define r_rowsToCopy        r9
  39.  
  40.     #define r_srcPixel            r10
  41.     #define r_dstPixel            r11
  42.     #define r_index                r12
  43.     #define r_maskPixel            r0
  44.  
  45.     ASM_BEGIN
  46.  
  47.     rlwinm    r10,r_numBytesPerRow,0,31,31                // numBytesPerRow & 1
  48.     rlwinm    r11,r_numBytesPerRow,31,31,31                // numBytesPerRow & 2
  49.     rlwinm    r_numBytesPerRow,r_numBytesPerRow,30,2,31    // numBytesPerRow >> 2
  50.  
  51.     cmplwi    cr7,r10,0
  52.     cmplwi    cr6,r11,0
  53.     cmplwi    cr5,r_numBytesPerRow,0
  54.  
  55. @yloop:
  56.     li        r_index,0
  57.  
  58.     beq        cr5,@skipwords
  59.         mtctr    r_numBytesPerRow
  60.     @wordloop:
  61.         lwzx    r_maskPixel,r_maskPixelP,r_index
  62.         lwzx    r_dstPixel,r_dstPixelP,r_index
  63.         lwzx    r_srcPixel,r_srcPixelP,r_index
  64.         and        r_dstPixel,r_dstPixel,r_maskPixel
  65.         or        r_maskPixel,r_srcPixel,r_dstPixel
  66.         stwx    r_maskPixel,r_dstPixelP,r_index
  67.         addi    r_index,r_index,4
  68.         bdnz    @wordloop
  69.     @skipwords:
  70.  
  71.     beq        cr6,@skipshort
  72.         lhzx    r_maskPixel,r_maskPixelP,r_index
  73.         lhzx    r_dstPixel,r_dstPixelP,r_index
  74.         lhzx    r_srcPixel,r_srcPixelP,r_index
  75.         and        r_dstPixel,r_dstPixel,r_maskPixel
  76.         or        r_maskPixel,r_srcPixel,r_dstPixel
  77.         sthx    r_maskPixel,r_dstPixelP,r_index
  78.         addi    r_index,r_index,2
  79.     @skipshort:    
  80.  
  81.     beq        cr7,@skipbyte
  82.         lbzx    r_maskPixel,r_maskPixelP,r_index
  83.         lbzx    r_dstPixel,r_dstPixelP,r_index
  84.         lbzx    r_srcPixel,r_srcPixelP,r_index
  85.         and        r_dstPixel,r_dstPixel,r_maskPixel
  86.         or        r_maskPixel,r_srcPixel,r_dstPixel
  87.         stbx    r_maskPixel,r_dstPixelP,r_index
  88.         addi    r_index,r_index,1
  89.     @skipbyte:    
  90.  
  91.     subic.    r_rowsToCopy,r_rowsToCopy,1
  92.     
  93.     add        r_srcPixelP,r_srcPixelP,r_srcOffset
  94.     add        r_dstPixelP,r_dstPixelP,r_dstOffset
  95.     add        r_maskPixelP,r_maskPixelP,r_srcOffset
  96.     
  97.     bne        @yloop
  98.     
  99.     ASM_END
  100. }
  101.  
  102. ///--------------------------------------------------------------------------------------
  103. //        BlitPixiePartialMask - PowerPC asm implementation by Anders F Björklund
  104. ///--------------------------------------------------------------------------------------
  105.  
  106. ASM_FUNC void BlitPixiePartialMask(
  107.     register unsigned char *srcPixelP,        // r3
  108.     register unsigned char *dstPixelP,        // r4
  109.     register unsigned char *maskPixelP,        // r5
  110.     register unsigned long srcOffset,        // r6
  111.     register unsigned long dstOffset,        // r7
  112.     register unsigned short numBytesPerRow,    // r8
  113.     register unsigned short rowsToCopy)        // r9
  114. {
  115.     #define r_srcPixelP            r3
  116.     #define r_dstPixelP            r4
  117.     #define r_maskPixelP        r5
  118.     #define r_srcOffset            r6
  119.     #define r_dstOffset            r7
  120.     #define r_numBytesPerRow    r8
  121.     #define r_rowsToCopy        r9
  122.  
  123.     #define r_srcPixel            r10
  124.     #define r_dstPixel            r11
  125.     #define r_index                r12
  126.     #define r_maskPixel            r0
  127.  
  128.     ASM_BEGIN
  129.     
  130.     rlwinm    r10,r_numBytesPerRow,0,31,31                // numBytesPerRow & 1
  131.     rlwinm    r11,r_numBytesPerRow,31,31,31                // numBytesPerRow & 2
  132.     rlwinm    r_numBytesPerRow,r_numBytesPerRow,30,2,31    // numBytesPerRow >> 2
  133.  
  134.     cmplwi    cr7,r10,0
  135.     cmplwi    cr6,r11,0
  136.     cmplwi    cr5,r_numBytesPerRow,0
  137.  
  138. @yloop:
  139.     li        r_index,0
  140.  
  141.     beq        cr5,@skipwords
  142.         mtctr    numBytesPerRow
  143.     @wordloop:
  144.         lwzx    r_maskPixel,r_maskPixelP,r_index
  145.         lwzx    r_srcPixel,r_srcPixelP,r_index
  146.         lwzx    r_dstPixel,r_dstPixelP,r_index
  147.         andc    r_srcPixel,r_srcPixel,r_maskPixel
  148.         and        r_dstPixel,r_dstPixel,r_maskPixel
  149.         or        r_maskPixel,r_srcPixel,r_dstPixel
  150.         stwx    r_maskPixel,r_dstPixelP,r_index
  151.         addi    r_index,r_index,4
  152.         bdnz    @wordloop
  153.     @skipwords:
  154.  
  155.     beq        cr6,@skipshort
  156.         lhzx    r_maskPixel,r_maskPixelP,r_index
  157.         lhzx    r_srcPixel,r_srcPixelP,r_index
  158.         lhzx    r_dstPixel,r_dstPixelP,r_index
  159.         andc    r_srcPixel,r_srcPixel,r_maskPixel
  160.         and        r_dstPixel,r_dstPixel,r_maskPixel
  161.         or        r_maskPixel,r_srcPixel,r_dstPixel
  162.         sthx    r_maskPixel,r_dstPixelP,r_index
  163.         addi    r_index,r_index,2
  164.     @skipshort:    
  165.  
  166.     beq        cr7,@skipbyte
  167.         lbzx    r_maskPixel,maskPixelP,r_index
  168.         lbzx    r_srcPixel,r_srcPixelP,r_index
  169.         lbzx    r_dstPixel,r_dstPixelP,r_index
  170.         andc    r_srcPixel,r_srcPixel,r_maskPixel
  171.         and        r_dstPixel,r_dstPixel,r_maskPixel
  172.         or        r_maskPixel,r_srcPixel,r_dstPixel
  173.         stbx    r_maskPixel,r_dstPixelP,r_index
  174.         addi    r_index,r_index,1
  175.     @skipbyte:    
  176.  
  177.     subic.    r_rowsToCopy,r_rowsToCopy,1
  178.     
  179.     add        r_srcPixelP,r_srcPixelP,r_srcOffset
  180.     add        r_dstPixelP,r_dstPixelP,r_dstOffset
  181.     add        r_maskPixelP,r_maskPixelP,r_srcOffset
  182.     
  183.     bne        @yloop
  184.  
  185.     ASM_END
  186. }
  187.  
  188. #pragma mark *** 680X0 asm:
  189. #elif USE_68K_ASSEMBLY
  190.  
  191. ///--------------------------------------------------------------------------------------
  192. //        BlitPixieMask
  193. ///--------------------------------------------------------------------------------------
  194.  
  195. ASM_FUNC void BlitPixieMask(
  196.     register unsigned char *srcPixelP,
  197.     register unsigned char *dstPixelP,
  198.     register unsigned char *maskPixelP,
  199.     register unsigned long srcRowStride,
  200.     register unsigned long dstRowStride,
  201.     register unsigned short numBytesPerRow,
  202.     register unsigned short rowsToCopy)
  203. {
  204.     register unsigned long loopsPerRow;
  205.     
  206.     ASM_BEGIN
  207.  
  208.         ext.l    numBytesPerRow
  209.         sub.l    numBytesPerRow, srcRowStride
  210.         sub.l    numBytesPerRow, dstRowStride
  211.         
  212.             // longWordsPerRow = numBytesPerRow >> 2;
  213.         move.l    numBytesPerRow, d0
  214.         lsr.l    #2, d0
  215.  
  216.             // numBytesPerRow -= longWordsPerRow << 2;
  217.         move.l    d0, d1
  218.         lsl.l    #2, d1
  219.         sub.l    d1, numBytesPerRow
  220.  
  221.             // loopsPerRow = longWordsPerRow >> 4;
  222.         move.l    d0, loopsPerRow
  223.         lsr.l    #4, loopsPerRow
  224.  
  225.             
  226.         moveq    #0xF, d1
  227.         and.l    d1, d0
  228.         lsl.l    #3, d0                    // longWordsPerRow *= 8;
  229.         lea     @loopEnd, a0            // get address of the end of the loop
  230.         sub.l    d0, a0                    // calculate where to jmp in the loop
  231.  
  232.     @forEachRow:
  233.         move.l    loopsPerRow, d2
  234.         jmp        (a0)
  235.     @loopBase:
  236.             // 16
  237.         move.l    (dstPixelP), d0
  238.         and.l    (maskPixelP)+, d0
  239.         or.l    (srcPixelP)+, d0
  240.         move.l    d0, (dstPixelP)+
  241.             // 15
  242.         move.l    (dstPixelP), d0
  243.         and.l    (maskPixelP)+, d0
  244.         or.l    (srcPixelP)+, d0
  245.         move.l    d0, (dstPixelP)+
  246.             // 14
  247.         move.l    (dstPixelP), d0
  248.         and.l    (maskPixelP)+, d0
  249.         or.l    (srcPixelP)+, d0
  250.         move.l    d0, (dstPixelP)+
  251.           // 13
  252.         move.l    (dstPixelP), d0
  253.         and.l    (maskPixelP)+, d0
  254.         or.l    (srcPixelP)+, d0
  255.         move.l    d0, (dstPixelP)+
  256.           // 12
  257.         move.l    (dstPixelP), d0
  258.         and.l    (maskPixelP)+, d0
  259.         or.l    (srcPixelP)+, d0
  260.         move.l    d0, (dstPixelP)+
  261.           // 11
  262.         move.l    (dstPixelP), d0
  263.         and.l    (maskPixelP)+, d0
  264.         or.l    (srcPixelP)+, d0
  265.         move.l    d0, (dstPixelP)+
  266.           // 10
  267.         move.l    (dstPixelP), d0
  268.         and.l    (maskPixelP)+, d0
  269.         or.l    (srcPixelP)+, d0
  270.         move.l    d0, (dstPixelP)+
  271.           //  9
  272.         move.l    (dstPixelP), d0
  273.         and.l    (maskPixelP)+, d0
  274.         or.l    (srcPixelP)+, d0
  275.         move.l    d0, (dstPixelP)+
  276.           //  8
  277.         move.l    (dstPixelP), d0
  278.         and.l    (maskPixelP)+, d0
  279.         or.l    (srcPixelP)+, d0
  280.         move.l    d0, (dstPixelP)+
  281.           //  7
  282.         move.l    (dstPixelP), d0
  283.         and.l    (maskPixelP)+, d0
  284.         or.l    (srcPixelP)+, d0
  285.         move.l    d0, (dstPixelP)+
  286.             //  6
  287.         move.l    (dstPixelP), d0
  288.         and.l    (maskPixelP)+, d0
  289.         or.l    (srcPixelP)+, d0
  290.         move.l    d0, (dstPixelP)+
  291.           //  5
  292.         move.l    (dstPixelP), d0
  293.         and.l    (maskPixelP)+, d0
  294.         or.l    (srcPixelP)+, d0
  295.         move.l    d0, (dstPixelP)+
  296.           //  4
  297.         move.l    (dstPixelP), d0
  298.         and.l    (maskPixelP)+, d0
  299.         or.l    (srcPixelP)+, d0
  300.         move.l    d0, (dstPixelP)+
  301.           //  3
  302.         move.l    (dstPixelP), d0
  303.         and.l    (maskPixelP)+, d0
  304.         or.l    (srcPixelP)+, d0
  305.         move.l    d0, (dstPixelP)+
  306.         //  2
  307.         move.l    (dstPixelP), d0
  308.         and.l    (maskPixelP)+, d0
  309.         or.l    (srcPixelP)+, d0
  310.         move.l    d0, (dstPixelP)+
  311.           //  1
  312.         move.l    (dstPixelP), d0
  313.         and.l    (maskPixelP)+, d0
  314.         or.l    (srcPixelP)+, d0
  315.         move.l    d0, (dstPixelP)+
  316.     @loopEnd:
  317.         subq.l    #1, d2
  318.         bpl        @loopBase
  319.  
  320.         // now do any leftover bits
  321.         move.l    numBytesPerRow, d2
  322.         beq        @nextRow
  323.         subq.l    #2, d2
  324.         bmi        @moveByte
  325.         move.w    (dstPixelP), d0
  326.         and.w    (maskPixelP)+, d0
  327.         or.w    (srcPixelP)+, d0
  328.         move.w    d0, (dstPixelP)+
  329.         tst        d2
  330.         beq        @nextRow
  331.     @moveByte:    
  332.         move.b    (dstPixelP), d0
  333.         and.b    (maskPixelP)+, d0
  334.         or.b    (srcPixelP)+, d0
  335.         move.b    d0, (dstPixelP)+
  336.  
  337.     @nextRow:
  338.         adda.l    srcRowStride, srcPixelP
  339.         adda.l    srcRowStride, maskPixelP
  340.         adda.l    dstRowStride, dstPixelP
  341.     
  342.         subq.w    #1, rowsToCopy
  343.         bne        @forEachRow
  344.  
  345.     ASM_END
  346. }
  347.  
  348.  
  349.  
  350.  
  351. ///--------------------------------------------------------------------------------------
  352. //        BlitPixiePartialMask
  353. ///--------------------------------------------------------------------------------------
  354.  
  355. ASM_FUNC void BlitPixiePartialMask(
  356.     register unsigned char *srcPixelP,
  357.     register unsigned char *dstPixelP,
  358.     register unsigned char *maskPixelP,
  359.     register unsigned long srcRowStride,
  360.     register unsigned long dstRowStride,
  361.     register unsigned short numBytesPerRow,
  362.     register unsigned short rowsToCopy)
  363. {
  364.     register unsigned long loopsPerRow;
  365.  
  366.     ASM_BEGIN
  367.     
  368.         ext.l    numBytesPerRow
  369.         sub.l    numBytesPerRow, srcRowStride
  370.         sub.l    numBytesPerRow, dstRowStride
  371.  
  372.             // longWordsPerRow = numBytesPerRow >> 2;
  373.         moveq    #0,d0
  374.         move.w    numBytesPerRow, d0
  375.         lsr.l    #2, d0
  376.  
  377.             // numBytesPerRow -= longWordsPerRow << 2;
  378.         move.l    d0, d1
  379.         lsl.l    #2, d1
  380.         sub.l    d1, numBytesPerRow
  381.  
  382.             // loopsPerRow = longWordsPerRow >> 4;
  383.         move.l    d0, loopsPerRow
  384.         lsr.l    #4, loopsPerRow
  385.  
  386.             
  387.         moveq    #0xF, d1
  388.         and.l    d1, d0
  389.         mulu    #14, d0                    // longWordsPerRow *= 14 (bytes in segment of loop)
  390.         lea     @loopEnd, a0            // get address of the end of the loop
  391.         sub.l    d0, a0                    // calculate where to jmp in the loop
  392.  
  393.     @forEachRow:
  394.         move.l    loopsPerRow, d2
  395.         jmp        (a0)
  396.     @loopBase:
  397.             // 16
  398.         move.l    (dstPixelP), d0
  399.         and.l    (maskPixelP), d0
  400.         move.l    (maskPixelP)+, d1
  401.         not.l    d1
  402.         and.l    (srcPixelP)+, d1
  403.         or.l    d1, d0
  404.         move.l    d0, (dstPixelP)+
  405.             // 15
  406.         move.l    (dstPixelP), d0
  407.         and.l    (maskPixelP), d0
  408.         move.l    (maskPixelP)+, d1
  409.         not.l    d1
  410.         and.l    (srcPixelP)+, d1
  411.         or.l    d1, d0
  412.         move.l    d0, (dstPixelP)+
  413.             // 14
  414.         move.l    (dstPixelP), d0
  415.         and.l    (maskPixelP), d0
  416.         move.l    (maskPixelP)+, d1
  417.         not.l    d1
  418.         and.l    (srcPixelP)+, d1
  419.         or.l    d1, d0
  420.         move.l    d0, (dstPixelP)+
  421.           // 13
  422.         move.l    (dstPixelP), d0
  423.         and.l    (maskPixelP), d0
  424.         move.l    (maskPixelP)+, d1
  425.         not.l    d1
  426.         and.l    (srcPixelP)+, d1
  427.         or.l    d1, d0
  428.         move.l    d0, (dstPixelP)+
  429.           // 12
  430.         move.l    (dstPixelP), d0
  431.         and.l    (maskPixelP), d0
  432.         move.l    (maskPixelP)+, d1
  433.         not.l    d1
  434.         and.l    (srcPixelP)+, d1
  435.         or.l    d1, d0
  436.         move.l    d0, (dstPixelP)+
  437.           // 11
  438.         move.l    (dstPixelP), d0
  439.         and.l    (maskPixelP), d0
  440.         move.l    (maskPixelP)+, d1
  441.         not.l    d1
  442.         and.l    (srcPixelP)+, d1
  443.         or.l    d1, d0
  444.         move.l    d0, (dstPixelP)+
  445.           // 10
  446.         move.l    (dstPixelP), d0
  447.         and.l    (maskPixelP), d0
  448.         move.l    (maskPixelP)+, d1
  449.         not.l    d1
  450.         and.l    (srcPixelP)+, d1
  451.         or.l    d1, d0
  452.         move.l    d0, (dstPixelP)+
  453.           //  9
  454.         move.l    (dstPixelP), d0
  455.         and.l    (maskPixelP), d0
  456.         move.l    (maskPixelP)+, d1
  457.         not.l    d1
  458.         and.l    (srcPixelP)+, d1
  459.         or.l    d1, d0
  460.         move.l    d0, (dstPixelP)+
  461.           //  8
  462.         move.l    (dstPixelP), d0
  463.         and.l    (maskPixelP), d0
  464.         move.l    (maskPixelP)+, d1
  465.         not.l    d1
  466.         and.l    (srcPixelP)+, d1
  467.         or.l    d1, d0
  468.         move.l    d0, (dstPixelP)+
  469.           //  7
  470.         move.l    (dstPixelP), d0
  471.         and.l    (maskPixelP), d0
  472.         move.l    (maskPixelP)+, d1
  473.         not.l    d1
  474.         and.l    (srcPixelP)+, d1
  475.         or.l    d1, d0
  476.         move.l    d0, (dstPixelP)+
  477.             //  6
  478.         move.l    (dstPixelP), d0
  479.         and.l    (maskPixelP), d0
  480.         move.l    (maskPixelP)+, d1
  481.         not.l    d1
  482.         and.l    (srcPixelP)+, d1
  483.         or.l    d1, d0
  484.         move.l    d0, (dstPixelP)+
  485.           //  5
  486.         move.l    (dstPixelP), d0
  487.         and.l    (maskPixelP), d0
  488.         move.l    (maskPixelP)+, d1
  489.         not.l    d1
  490.         and.l    (srcPixelP)+, d1
  491.         or.l    d1, d0
  492.         move.l    d0, (dstPixelP)+
  493.           //  4
  494.         move.l    (dstPixelP), d0
  495.         and.l    (maskPixelP), d0
  496.         move.l    (maskPixelP)+, d1
  497.         not.l    d1
  498.         and.l    (srcPixelP)+, d1
  499.         or.l    d1, d0
  500.         move.l    d0, (dstPixelP)+
  501.           //  3
  502.         move.l    (dstPixelP), d0
  503.         and.l    (maskPixelP), d0
  504.         move.l    (maskPixelP)+, d1
  505.         not.l    d1
  506.         and.l    (srcPixelP)+, d1
  507.         or.l    d1, d0
  508.         move.l    d0, (dstPixelP)+
  509.         //  2
  510.         move.l    (dstPixelP), d0
  511.         and.l    (maskPixelP), d0
  512.         move.l    (maskPixelP)+, d1
  513.         not.l    d1
  514.         and.l    (srcPixelP)+, d1
  515.         or.l    d1, d0
  516.         move.l    d0, (dstPixelP)+
  517.           //  1
  518.         move.l    (dstPixelP), d0
  519.         and.l    (maskPixelP), d0
  520.         move.l    (maskPixelP)+, d1
  521.         not.l    d1
  522.         and.l    (srcPixelP)+, d1
  523.         or.l    d1, d0
  524.         move.l    d0, (dstPixelP)+
  525.     @loopEnd:
  526.         subq.l    #1, d2
  527.         bpl        @loopBase
  528.  
  529.         // now do any leftover bits
  530.         move.l    numBytesPerRow, d2
  531.         beq        @nextRow
  532.         subq.l    #2, d2
  533.         bmi        @moveByte
  534.         move.w    (dstPixelP), d0
  535.         and.w    (maskPixelP), d0
  536.         move.w    (maskPixelP)+, d1
  537.         not.w    d1
  538.         and.w    (srcPixelP)+, d1
  539.         or.w    d1, d0
  540.         move.w    d0, (dstPixelP)+
  541.         tst        d2
  542.         beq        @nextRow
  543.     @moveByte:
  544.         move.b    (dstPixelP), d0
  545.         and.b    (maskPixelP), d0
  546.         move.b    (maskPixelP)+, d1
  547.         not.b    d1
  548.         and.b    (srcPixelP)+, d1
  549.         or.b    d1, d0
  550.         move.b    d0, (dstPixelP)+
  551.  
  552.     @nextRow:
  553.         adda.l    srcRowStride, srcPixelP
  554.         adda.l    srcRowStride, maskPixelP
  555.         adda.l    dstRowStride, dstPixelP
  556.     
  557.         subq.w    #1, rowsToCopy
  558.         bne        @forEachRow
  559.  
  560.     ASM_END
  561. }
  562.  
  563. #pragma mark *** Generic C:
  564. #elif USE_GENERIC_C
  565.  
  566. ///--------------------------------------------------------------------------------------
  567. //        BlitPixieMask
  568. ///--------------------------------------------------------------------------------------
  569.  
  570. void BlitPixieMask(
  571.     unsigned char *srcPixelP,
  572.     unsigned char *dstPixelP,
  573.     unsigned char *maskPixelP,
  574.     unsigned long srcOffset,
  575.     unsigned long dstOffset,
  576.     unsigned short numBytesPerRow,
  577.     unsigned short rowsToCopy)
  578. {
  579.     unsigned long index;
  580.     
  581.     srcOffset -= numBytesPerRow;
  582.     dstOffset -= numBytesPerRow;
  583.     
  584.     while (rowsToCopy--)    
  585.     {
  586.         for (index = 0; index < numBytesPerRow; index++)
  587.         {
  588.             *dstPixelP++ = (*dstPixelP & *maskPixelP++) | *srcPixelP++;
  589.         }
  590.         
  591.             // bump to next row
  592.         srcPixelP += srcOffset;
  593.         dstPixelP += dstOffset;
  594.         maskPixelP += srcOffset;
  595.     }
  596. }
  597.  
  598. ///--------------------------------------------------------------------------------------
  599. //        BlitPixiePartialMask
  600. ///--------------------------------------------------------------------------------------
  601.  
  602. void BlitPixiePartialMask(
  603.     unsigned char *srcPixelP,
  604.     unsigned char *dstPixelP,
  605.     unsigned char *maskPixelP,
  606.     unsigned long srcOffset,
  607.     unsigned long dstOffset,
  608.     unsigned short numBytesPerRow,
  609.     unsigned short rowsToCopy)
  610. {
  611.     unsigned long index;
  612.     unsigned char mask;
  613.     
  614.     srcOffset -= numBytesPerRow;
  615.     dstOffset -= numBytesPerRow;
  616.     
  617.     while (rowsToCopy--)    
  618.     {
  619.         for (index = 0; index < numBytesPerRow; index++)
  620.         {
  621.             mask = *maskPixelP++;
  622.             *dstPixelP++ = (*dstPixelP & mask) | (*srcPixelP++ &~ mask);
  623.         }
  624.         
  625.             // bump to next row
  626.         srcPixelP += srcOffset;
  627.         dstPixelP += dstOffset;
  628.         maskPixelP += srcOffset;
  629.     }
  630. }
  631.  
  632. #endif
  633.  
  634. #pragma mark -
  635.  
  636. #ifndef GENERATINGASM // do not include for asm file generation
  637.  
  638. ///--------------------------------------------------------------------------------------
  639. //        BlitPixieMaskColor
  640. ///--------------------------------------------------------------------------------------
  641.  
  642. void BlitPixieMaskColor(
  643.     unsigned long srcColor,
  644.     unsigned char *dstPixelP,
  645.     unsigned char *maskPixelP,
  646.     unsigned long srcOffset,
  647.     unsigned long dstOffset,
  648.     unsigned short numBytesPerRow,
  649.     unsigned short rowsToCopy)
  650. {
  651.     unsigned long index;
  652.     unsigned long mask;
  653.     
  654.     srcOffset -= numBytesPerRow;
  655.     dstOffset -= numBytesPerRow;
  656.     
  657.     while (rowsToCopy--)    
  658.     {
  659.         // note: must do this with longs and shorts first, since depth can be both 32, 16 or 8 bits
  660.         
  661.         for ( index=0; index < (numBytesPerRow >> 2); index++)
  662.         {
  663.             mask = *((unsigned long *) maskPixelP);
  664.             maskPixelP += sizeof(unsigned long);
  665.             *((unsigned long *) dstPixelP) = (*((unsigned long *) dstPixelP) & mask) | (srcColor &~ mask);
  666.             dstPixelP += sizeof(unsigned long);
  667.         }
  668.  
  669.         if ( numBytesPerRow & 2 )
  670.         {
  671.             mask = *((unsigned short *) maskPixelP);
  672.             maskPixelP += sizeof(unsigned short);
  673.             *((unsigned short *) dstPixelP) = (*((unsigned short *) dstPixelP) & mask) | (srcColor &~ mask);
  674.             dstPixelP += sizeof(unsigned short);
  675.         }
  676.  
  677.         if ( numBytesPerRow & 1 )
  678.         {
  679.             mask = *maskPixelP++;
  680.             *dstPixelP++ = (*dstPixelP & mask) | (srcColor &~ mask);
  681.         }
  682.         
  683.             // bump to next row
  684.         dstPixelP += dstOffset;
  685.         maskPixelP += srcOffset;
  686.     }
  687. }
  688.  
  689. #endif
  690.